#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
@File Name: 实现排序_sort1.py
@Author: LT
@Date: 2021/10/20 9:55
# -----------------------------------------------------------------------------------------------------
@Description: 
write here
# -----------------------------------------------------------------------------------------------------
"""


def custom_sort(list, field: "just an index"):
    res = []
    for x in list:
        i = 0
        for y in res:
            if x[field] <= y[field]:
                break
            i += 1
        res[i:1] = [x]
    return res


if __name__ == '__main__':
    table = [{'name': 'john', 'age': 25}, {'name': 'doe', 'age': 32}]
    print(custom_sort(table, 'name'))
    print(custom_sort(table, 'age'))
    table = [('john', 25), ('doe', 32)]
    print(custom_sort(table, 0))
    print(custom_sort(table, 1))
    pass
